<template>
  <div class="loginbody">
    <div class="logindata">
      <div class="logintext">
        <h2>Aurora College</h2>
      </div>
      <div class="formdata">
        <el-form ref="form" :model="form" :rules="rules">
          <el-form-item prop="account" style="border-radius: 30px">
            <el-input v-model="form.account" clearable placeholder="请输入账号"></el-input>
          </el-form-item>
          <el-form-item prop="password" style="border-radius: 30px">
            <el-input v-model="form.password" clearable placeholder="请输入密码" show-password>
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="tool">
        <div>
          <el-checkbox style="color:#C0C4CC" v-model="checked" @change="remenber">记住密码</el-checkbox>
        </div>
        <div>
          <span class="shou" @click="forgetpas" style="color:#C0C4CC">忘记密码？</span>
        </div>
      </div>
      <div class="butt">
        <el-button @click="openFullScreen" v-loading.fullscreen.lock="fullscreenLoading" type="primary" round
                   @click.native.prevent="login('form')" style="width: 150px;">登录
        </el-button>
        <!-- <el-button type="primary" @click.native.prevent="login('form')"
          >登录</el-button>
        <el-button class="shou" @click="register">注册</el-button> -->
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      fullscreenLoading: false,
      form: {
        password: "",
        account: "",
      },
      checked: false,
      rules: {
        account: [{
          required: true,
          message: "请输入用户名",
          trigger: "blur"
        },
          {
            max: 10,
            message: "不能大于10个字符",
            trigger: "blur"
          },
        ],
        password: [{
          required: true,
          message: "请输入密码",
          trigger: "blur"
        },
          {
            max: 10,
            message: "不能大于10个字符",
            trigger: "blur"
          },
        ],
      },
    };
  },
  // mounted() {
  //   if (localStorage.getItem("news")) {
  //     this.form = JSON.parse(localStorage.getItem("news"))
  //     this.checked = true
  //   }
  // },
  methods: {
    login(form) {
      var data = this.form;
      var _this = this;
      console.log(form)
      this.$refs[form].validate((valid) => {
        console.log(valid)
        if (valid) {
          // console.log(login)
          var url = 'http://127.0.0.1:8080/userinfo/login';
          axios.get(url, {
            params: {
              password: data.password,
              account: data.account,
            }
          }).then((res) => {
                console.log(res)
                if (res.data.code === 0) {
                  window.localStorage.setItem("user", JSON.stringify(res.data.data));
                  _this.$router.push("/");
                  console.log("跳转")
                  _this.$message({
                    message: "登录成功啦",
                    type: "success",
                    showClose: true,
                  });
                } else {
                  _this.$message({
                    message: "账户名或密码错误",
                    type: "error",
                    showClose: true,
                  });
                }
              })
        } else {
          return false;
        }
      });
    },
    remenber(data) {
      this.checked = data
      if (this.checked) {
        localStorage.setItem("news", JSON.stringify(this.form))
      } else {
        localStorage.removeItem("news")
      }
    },
    forgetpas() {
      this.$message({
        type: "info",
        message: "功能尚未开发额😥",
        showClose: true
      })
    },
    register() {
    },
    openFullScreen() {
      this.fullscreenLoading = true;
      setTimeout(() => {
        this.fullscreenLoading = false;
      }, 2000);
    },
    openFullScreen() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      setTimeout(() => {
        loading.close();
      }, 2000);
    }
  },

}
</script>


<style scoped>
body {
  margin: 0;
  padding: 0;
}

.loginbody {
  width: 100%;
  height: 100%;
  min-width: 1000px;
  background-image: url("../assets/login3.png");
  background-size: 100% 100%;
  background-position: center center;
  overflow: auto;
  background-repeat: no-repeat;
  position: absolute;
  top: 0;
  left: 0;
  line-height: 100%;
  padding-top: 150px;
  margin-top: 0;
}

.logintext {
  margin-bottom: 20px;
  line-height: 50px;
  text-align: center;
  font-size: 30px;
  font-weight: bolder;
  color: white;
  text-shadow: 2px 2px 4px #000000;
}

.logindata {
  width: 400px;
  height: 300px;
  transform: translate(-50%);
  margin-left: 50%;
}

.tool {
  display: flex;
  justify-content: space-between;
  color: #606266;
}

.butt {
  margin-top: 10px;
  text-align: center;
}

.shou {
  cursor: pointer;
  color: #606266;
}

/*ui*/
/* /deep/ .el-form-item__label {
    font-weight: bolder;
    font-size: 15px;
    text-align: left;
  }

  /deep/ .el-button {
    width: 100%;
    margin-bottom: 10px;

  } */


</style>
